package com.spa.interfaces.admin;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.spa.application.command.admin.MassagistAdminEditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.*;
import com.spa.application.query.admin.MassagitsFinanceQuery;
import com.spa.application.query.admin.MassagitsPageQuery;
import com.spa.application.query.admin.MassagitsServiceTimePageQuery;
import com.spa.application.query.admin.MassagitsonoffPageQuery;
import com.spa.application.service.admin.MassagistApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("admin/messagist")
public class MassagistController extends BaseController {

    @Autowired
    private MassagistApplicationService massagistApplicationService;

    @PostMapping("edit")
    public ResponseMessage edit(@RequestBody MassagistAdminEditCommand command) {
        Assert.isFalse( ObjectUtil.isNull(command.getMassagistId()) || 0L == command.getMassagistId() , "缺少技师关键信息");
        massagistApplicationService.edit(command);
        return responseHelper.success();
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<MassagistAdminListDTO>> page(@RequestBody MassagitsPageQuery query) {
        return responseHelper.success(massagistApplicationService.page(query));
    }

    @PostMapping("exportMassage")
    public void exportMassage(HttpServletResponse response,@RequestBody MassagitsPageQuery query) throws Exception {
        List<MassagistExportDTO> list = massagistApplicationService.list(query);
        exportQueryResult(response, list , "技师列表", "技师列表", MassagistExportDTO.class);
    }

    @PostMapping("service/page")
    public ResponseMessage<PageResult<MassagistServiceTimeDTO>> servicePage(@RequestBody MassagitsServiceTimePageQuery query) {
        return responseHelper.success(massagistApplicationService.onoffTimePage(query));
    }

    @PostMapping("onoff/page")
    public ResponseMessage<PageResult<MassagistOnoffDTO>> onoffTimePage(@RequestBody MassagitsonoffPageQuery query) {
        return responseHelper.success(massagistApplicationService.onoffPage(query));
    }

    @PostMapping("exportOnoff")
    public void exportOnoff(HttpServletResponse response,@RequestBody MassagitsonoffPageQuery query) throws Exception {
        List<MassagistOnofExportDTO> list = massagistApplicationService.onoffList(query);
        exportQueryResult(response, list , "技师上下线记录", "技师上下线记录", MassagistOnofExportDTO.class);
    }

    @PostMapping("finance")
    public ResponseMessage<MassagistFinanceDTO> finance(@RequestBody MassagitsFinanceQuery query) {
        return responseHelper.success(massagistApplicationService.finance(query));
    }

    @PostMapping("remove")
    public ResponseMessage<MassagistFinanceDTO> remove(@RequestBody MassagitsFinanceQuery query) {
        Assert.isFalse( ObjectUtil.isNull(query.getMassagistId()) || 0L == query.getMassagistId() , "缺少技师关键信息");

        return responseHelper.success(massagistApplicationService.removeMassagits(query.getMassagistId()));
    }

    @PostMapping("query/messageinfo")
    public ResponseMessage<MassagistAdminEditDTO> queryMassagistInfo(@RequestBody MassagitsFinanceQuery query) {
        Assert.isFalse( ObjectUtil.isNull(query.getMassagistId()) || 0L == query.getMassagistId() , "缺少技师关键信息");
        return responseHelper.success(massagistApplicationService.queryInfo(query.getMassagistId()));
    }

}
